[김은애] sprint4#75
Hidden character warning
Conversation
…n into 김은애-sprint3
| public class AuthController { | ||
| private final AuthService authService; | ||
|
|
||
| @GetMapping("/login") |
There was a problem hiding this comment.
GET 방식의 URL에 정보가 존재할 경우 패스워드와 같은 숨겨야하는 정보가 노출될 수 있어 POST 방식의 RequestBody으로 처리 권장드려요.
| @RequestParam String username, | ||
| @RequestParam String password | ||
| ){ | ||
| UserLoginReqDto dto = new UserLoginReqDto(username, password); |
There was a problem hiding this comment.
추가적으로, Post 방식으로 호출할 경우 UserLoginReqDto로 변환처리가 필요 없을 것 같아요
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @Controller |
There was a problem hiding this comment.
@controller로는 기본적으로 템플릿 명으로 해석되기 때문에 @RestController 사용을 권장드려요.
| public class ChannelController { | ||
| private final ChannelService channelService; | ||
|
|
||
| @PostMapping("/public/create") |
There was a problem hiding this comment.
Restful API 설계상 URL에는 명사만 존재하는걸 권장하기 때문에 행위에 해당하는 create 사용보다는 api/channel/public-channel 식으로 하는걸 권장드려요. 다만 심화 요구사항을 보니 다음 수업때 RestFul API에 관한 설명이 있을 것으로 보여 현시점에서는 참고정도로 부탁드립니다.
| return ResponseEntity.ok(result); | ||
| } | ||
|
|
||
| @PatchMapping("/public/edit/{channelId}") |
|
|
||
| } | ||
|
|
||
| @GetMapping("/list/{userId}") |
There was a problem hiding this comment.
@PathVariable 보다는 @RequestParam이 어떠실까요?
채널 리스트를 가져오지만 검색 조건(사용자 ID)에 의해 응답하므로 @RequestParam이 더 타당해보였습니다.
또한 코드를 보지 않고 판단할 경우 UserId 값이 들어갈 부분에 ChannelId로 파악될 수 있어 보여서요.
|
|
||
| import java.util.NoSuchElementException; | ||
|
|
||
| @ControllerAdvice |
There was a problem hiding this comment.
@RestControllerAdvice가 어떠실까요?
마찬가지로 @ControllerAdvice는 View 기반(템플릿명)으로 동작하기 때문에 JSON 기반으로 동작하는 RestControllerAdvice를 권장드려요.
| import java.util.NoSuchElementException; | ||
|
|
||
| @ControllerAdvice | ||
| @ResponseBody |
There was a problem hiding this comment.
@RestControllerAdvice를 사용하면 @responsebody를 사용하지 않아도 됩니다.
@RestControllerAdvice = @ControllerAdvice + @ResponseBody
| @PathVariable UUID userId | ||
| ){ | ||
| userService.delete(userId); | ||
| return ResponseEntity.ok("user: " + userId + "가 삭제되었습니다."); |
There was a problem hiding this comment.
리소스(자원, 사용자)이 삭제되어서 자원이 더 이상 없다는걸 의미해주는 noContent().build()를 활용하시면 어떨까요!?
| }); | ||
| User user = userService.create(userCreateReqDto, binaryDto); | ||
| UserDto result = userService.find(user.getId()); | ||
| return ResponseEntity.ok(result); |
There was a problem hiding this comment.
URI location = URI.create("/users/" + user.getId());
return ResponseEntity
.created(location)
.body(result);
이렇게 201일 경우 자원이 생성되었다는 것을 알 수 있는 created 활용해보시는거 어떠세요?!?
| import org.springframework.web.bind.annotation.ResponseBody; | ||
|
|
||
| import java.util.NoSuchElementException; | ||
|
|
There was a problem hiding this comment.
추가적으로 controller 패키지 하위보다는 common 패키지 생성 및 하위에 위치시키면 어떨까요?!
|
요구사항
기본
심화
주요 변경사항
멘토에게